package com.ykg.controller;

import com.ykg.annotation.PassToken;
import com.ykg.dto.ContractDTO;
import com.ykg.dto.NoticeDTO;
import com.ykg.enums.ResultEnum;
import com.ykg.interceptor.ScopeLevel;
import com.ykg.pojo.Contract;
import com.ykg.pojo.Goods;
import com.ykg.pojo.NoticeLetter;
import com.ykg.request.CheckContractRequest;
import com.ykg.request.CheckNoticeRequest;
import com.ykg.service.IContractService;
import com.ykg.service.IGoodsService;
import com.ykg.service.INoticeService;
import com.ykg.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * TODO
 * 类(接口)：
 * Created on 15:56 2021/6/24.
 *
 * @Author: laobian
 * @Description:
 */
@Api(tags = "货运大厅合同员Api")
@RestController
@RequestMapping("/api/contractor")
public class ContractorController {
    @Autowired
    private INoticeService noticeService;

    @Autowired
    private IContractService contractService;

    @Autowired
    private IGoodsService goodsService;

    /*
    通知单相关接口
     */
    //@PassToken
    @ApiOperation("获取所有的通知单")
    @GetMapping(value = "/notice/all",produces = "application/json")
    @ScopeLevel(value = 9)
    public ResultResponse findAllNotice(){
        List<NoticeLetter> noticeLetters = noticeService.getNoticeLetter();
        return new ResultResponse(noticeLetters);
    }

   // @PassToken
    @ApiOperation("获取某个通知单的具体信息")
    @GetMapping(value = "/notice/{noticeId}",produces = "application/json")
    @ScopeLevel(value = 9)

    public ResultResponse findNoticeById(@PathVariable("noticeId") String noticeId ){
        NoticeDTO noticeDTO = noticeService.noticeDetailed(noticeId);
        return new ResultResponse(noticeDTO);
    }

    //@PassToken
    @ApiOperation("生成通知单")
    @PostMapping(value = "notice/addNotice",produces = "application/json")
    @ScopeLevel(value = 9)

    public ResultResponse addNotice(@RequestBody CheckNoticeRequest checkNoticeRequest){
        if(Objects.isNull(checkNoticeRequest)){
            return new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        int status = noticeService.checkNotice(checkNoticeRequest);
        if(status==0){
            return new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse((ResultEnum.SUCCESS));
    }


    /*
    合同相关
     */
   // @PassToken
    @ApiOperation("获取所有的合同")
    @GetMapping(value = "/contract/all",produces = "application/json")
    @ScopeLevel(value = 9)
    public ResultResponse findAllContract(){
        List<Contract> contracts = contractService.getContract();
        return  new ResultResponse(contracts);
    }

    //@PassToken
    @ApiOperation("查看某个合同的详情")
    @GetMapping(value = "/contract/{contractId}",produces = "application/json")
    @ScopeLevel(value = 9)

    public  ResultResponse findContactById(@PathVariable(value = "contractId") String contractId){
        ContractDTO contractDTO = contractService.contractDetailed(contractId);
        if(Objects.isNull(contractDTO)){
            return new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        return new ResultResponse(contractDTO);
    }

    //@PassToken
    @ApiOperation("生成合同")
    @PostMapping(value = "/contract/addContract")
    @ScopeLevel(value = 9)

    public ResultResponse addContract(@RequestBody CheckContractRequest checkContractRequest){
        if(Objects.isNull(checkContractRequest)){
            return  new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        int status = contractService.checkContract(checkContractRequest);
        if(status==0){
            return new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse((ResultEnum.SUCCESS));

    }

    /*
    货品相关
     */
    //@PassToken
    @ApiOperation("查看货品的价格")
    @GetMapping(value = "/goods/price",produces = "application/json")
    @ScopeLevel(value = 9)

    public  ResultResponse getGoodsPrice(){
        Goods goods = goodsService.getGoodsPrice();
        return new ResultResponse(goods);
    }

}
